import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
const router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/question',
      component: () => import('@/page/question/index.vue'),
      meta: {
        title: '问题',
        keepAlive: true
      },
      children: [
        {
          path: 'question',
          name: 'question',
          component: () => import('@/page/question/question.vue'),
          meta: {
            title: '问题区',
            isQue: true,
            keepAlive: true
          }
        },
        {
          path: 'notice',
          name: 'notice',
          component: () => import('@/page/notice/notice.vue'),
          meta: {
            title: '公告区',
            keepAlive: true
          }
        }
      ]
    },
    {
      path: '/que-detail/:id',
      name: 'que-detail',
      component: () => import('@/page/detail/art-detail.vue'),
      meta: {
        title: '问题详情',
        // keepAlive: true
      }
    },
    {
      path: '/notice-detail/:id',
      component: () => import('@/page/detail/art-detail.vue'),
      name: 'notice-detail',
      meta: {
        title: '公告详情',
        // keepAlive: true
      }
    },
    {
      path: '/all-reply/:id',
      component: () => import('@/page/all-reply/all-reply.vue'),
      name: 'all-reply',
      meta: {
        title: '全部评论'
      }
    },
    {
      path: '*',
      component: () => import('@/page/error/404.vue'),
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
